<?php
    $baseUrl = $this->baseUrl('');
    $category = new Default_Model_Category();
    $resultCategory = $category->listCategory();
    if(count($resultCategory) > 0) :
        foreach($resultCategory as $value) {
            $menuData['items'][$value['id']] = $value;
            $menuData['parents'][$value['parents']][] = $value['id'];
        }
        
        function displayMenu($parents, $menuData, $url) {
            $items = '';
            if(isset($menuData['parents'][$parents])) {
                $items .= '<ul>';
                foreach($menuData['parents'][$parents] as $value) {
                    $items .= '<li>';
                    $items .= '<a href="'.$url.'danh-muc/'.$menuData['items'][$value]['url'].'-'.$menuData['items'][$value]['id'].'.html">'.$menuData['items'][$value]['name'].'</a>';
                    $items .= displayMenu($value, $menuData, $url);
                    $items .= '</li>';
                }
                $items .= '</ul>';
            }
            return $items;
        }
?>
<div class="blocks">
    <div class="heading-blocks">
        <h4>Danh mục sản phẩm</h4>
    </div>
    
    <div id="category">
        <?php echo displayMenu(1, $menuData, $baseUrl); ?>
    </div>
</div>
<!-- End .blocks -->
<?php endif; ?>